﻿<%@ Page Title="" Language="C#" MasterPageFile="~/ConfExpert.master" AutoEventWireup="true"
	CodeFile="StockV2.aspx.cs" Inherits="StockV2" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="content" ContentPlaceHolderID="phMain" runat="Server">
	<script type="text/javascript">
		function rowClick(s, e) {
			if (popupClick)
				e.cancel = true;

			popupClick = false;
		}

		function pop(productId) {
			grdRolls.PerformCallback(productId);
			var p = $("#imgSave")[0];
			p.style.visibility = "visible";
		}

		function pop2(productId) {
			var p = $("#imgSave")[0];
			p.style.visibility = "hidden";
			grdRolls.PerformCallback(productId);
		}

		function showFinishPopup() {
			popFinish.Show();
		}
		function showDetail(s, e) {
			popRolls.Show();
		}



		var textSeparator = ",";

		function OnListBoxSelectionChanged(listBox, args) {
			UpdateText();
		}

		function UpdateText() {
			var selectedItems = checkListBox.GetSelectedItems();
			checkComboBox.SetText(GetSelectedItemsText(selectedItems));
		}

		function SynchronizeListBoxValues(dropDown, args) {
			checkListBox.UnselectAll();
			var texts = dropDown.GetText().split(textSeparator);
			var values = GetValuesByTexts(texts);
			checkListBox.SelectValues(values);

			UpdateText(); // for remove non-existing texts
		}

		function GetSelectedItemsText(items) {
			var texts = [];
			for (var i = 0; i < items.length; i++)
				texts.push(items[i].text);
			return texts.join(textSeparator);
		}

		function GetValuesByTexts(texts) {
			var actualValues = [];
			var item;
			for (var i = 0; i < texts.length; i++) {
				item = checkListBox.FindItemByText(texts[i]);
				if (item != null)
					actualValues.push(item.value);
			}
			return actualValues;
		}
 

	</script>
	<dx:ASPxPopupControl ID="popRolls" runat="server" ClientInstanceName="popRolls" PopupAction="LeftMouseClick"
		Modal="True" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
		ClientIDMode="AutoID" Width="700px" Height="320px" ShowPageScrollbarWhenModal="false"
		FooterText="" HeaderText="Roll Details" ScrollBars="Auto">
		<ContentStyle VerticalAlign="Middle" HorizontalAlign="Center">
		</ContentStyle>
		<HeaderStyle HorizontalAlign="Center" />
		<ContentCollection>
			<dx:PopupControlContentControl>
				<table width="100%" border="0">
					<tr>
						<td>
							<dx:ASPxGridView ID="grdRolls" runat="server" AutoGenerateColumns="False" ClientIDMode="AutoID"
								ClientInstanceName="grdRolls" KeyFieldName="RollId" OnCustomCallback="grdRolls_OnCustomCallback"
								Width="100%">
								<ClientSideEvents EndCallback="function(s,e){showDetail(s,e);}"></ClientSideEvents>
								<Columns>
									<dx:GridViewCommandColumn Caption="Select" ShowInCustomizationForm="True" ShowSelectCheckbox="True"
										VisibleIndex="1">
									</dx:GridViewCommandColumn>
									<dx:GridViewDataTextColumn FieldName="RollId" ShowInCustomizationForm="True" VisibleIndex="2">
									</dx:GridViewDataTextColumn>
									<dx:GridViewDataTextColumn FieldName="Qty" ShowInCustomizationForm="True" VisibleIndex="3">
										<PropertiesTextEdit DisplayFormatString="#,##0.00 mt'.'">
										</PropertiesTextEdit>
									</dx:GridViewDataTextColumn>
									<dx:GridViewDataTextColumn FieldName="Season" ShowInCustomizationForm="True"
										VisibleIndex="4">
									</dx:GridViewDataTextColumn>
									<dx:GridViewDataTextColumn FieldName="CustomerCode" ShowInCustomizationForm="True"
										VisibleIndex="5">
									</dx:GridViewDataTextColumn>
									<dx:GridViewDataTextColumn FieldName="VendorCode" ShowInCustomizationForm="True"
										VisibleIndex="6">
									</dx:GridViewDataTextColumn>
								</Columns>
								<SettingsBehavior AllowDragDrop="False" AllowGroup="False" AllowSort="False" />
								<SettingsBehavior AllowDragDrop="False" AllowSort="False" AllowGroup="False"></SettingsBehavior>
								<SettingsPager Mode="ShowAllRecords">
								</SettingsPager>
								<Settings ShowVerticalScrollBar="True" />
								<Settings ShowVerticalScrollBar="True"></Settings>
								<Styles>
									<Header HorizontalAlign="Center" Wrap="True">
									</Header>
								</Styles>
							</dx:ASPxGridView>
						</td>
					</tr>
				</table>
				<table width="100%">
					<tr>
						<td align="right" style="background-color: #f4f4f4; width: 100%">
							<img id="imgSave" style="cursor: pointer" src="../Images/save2.png" width="32" height="32"
								title="Save" onclick="gvcRezerve.PerformCallback('rollSelection');popRolls.Hide();" />
							<img src="../Images/seperator.png" />
							<img style="cursor: pointer" src="../Images/close3.png" title="Cancel" onclick="popRolls.Hide();" />
						</td>
					</tr>
				</table>
			</dx:PopupControlContentControl>
		</ContentCollection>
	</dx:ASPxPopupControl>
	<dx:ASPxPopupControl ID="popFinish" runat="server" ClientInstanceName="popFinish"
		PopupAction="LeftMouseClick" Modal="True" PopupHorizontalAlign="WindowCenter"
		PopupVerticalAlign="WindowCenter" AllowResize="True" ClientIDMode="AutoID" Width="323px"
		Height="375px" ShowPageScrollbarWhenModal="false" FooterText="" HeaderText="Reservation Details"
		ScrollBars="Auto">
		<ContentStyle VerticalAlign="Middle" HorizontalAlign="Center">
		</ContentStyle>
		<ContentStyle VerticalAlign="Middle" HorizontalAlign="Center">
		</ContentStyle>
		<HeaderStyle HorizontalAlign="Center" />
		<ContentCollection>
			<dx:PopupControlContentControl>
				<table width="100%">
					<tr>
						<td align="center">
							<table width="50%">
								<tr>
									<td align="right">
										<dx:ASPxLabel ID="ASPxLabel1" runat="server" Text="Brand">
										</dx:ASPxLabel>
									</td>
									<td>
										<dx:ASPxComboBox ID="cmbBrand" runat="server" SelectedIndex="0" ValueType="System.Int32"
											DataSourceID="odsBrand" TextField="Name" ValueField="BrandId">
										</dx:ASPxComboBox>
										<asp:ObjectDataSource ID="odsBrand" runat="server" SelectMethod="Brands" TypeName="DataAccess">
										</asp:ObjectDataSource>
									</td>
								</tr>
								<tr>
									<td align="right">
										<dx:ASPxLabel ID="ASPxLabel2" runat="server" Text="Season">
										</dx:ASPxLabel>
									</td>
									<td>
										<dx:ASPxComboBox ID="cmbSeason" runat="server" SelectedIndex="0" ValueType="System.Int32"
											DataSourceID="odsSeason" TextField="Name" ValueField="SezonId">
										</dx:ASPxComboBox>
										<asp:ObjectDataSource ID="odsSeason" runat="server" SelectMethod="Seasons" TypeName="DataAccess">
										</asp:ObjectDataSource>
									</td>
								</tr>
								<tr>
									<td align="right">
										<dx:ASPxLabel ID="ASPxLabel3" runat="server" Text="Reservation Duration" Wrap="False">
										</dx:ASPxLabel>
									</td>
									<td>
										<dx:ASPxComboBox ID="cmbDuration" runat="server" SelectedIndex="1" ValueType="System.String">
											<Items>
												<dx:ListEditItem Text="1 week" Value="7" />
												<dx:ListEditItem Text="2 weeks" Value="14" Selected="True" />
												<dx:ListEditItem Text="1 month" Value="30" />
												<dx:ListEditItem Text="3 months" Value="90" />
												<dx:ListEditItem Text="6 months" Value="180" />
											</Items>
										</dx:ASPxComboBox>
									</td>
								</tr>
								<tr>
									<td align="right">
										<dx:ASPxLabel ID="ASPxLabel4" runat="server" Text="Order Ref." Wrap="False">
										</dx:ASPxLabel>
									</td>
									<td>
										<dx:ASPxTextBox ID="txtOrderRef" runat="server" Width="170px">
										</dx:ASPxTextBox>
									</td>
								</tr>
								<tr>
									<td align="right">
										<dx:ASPxLabel ID="ASPxLabel5" runat="server" Text="Reserved By" Wrap="False">
										</dx:ASPxLabel>
									</td>
									<td>
										<dx:ASPxTextBox ID="txtReservedBy" runat="server" Width="170px">
										</dx:ASPxTextBox>
									</td>
								</tr>
								<tr>
									<td align="right">
										<dx:ASPxLabel ID="ASPxLabel6" runat="server" Text="e-mail Address" Wrap="False">
										</dx:ASPxLabel>
									</td>
									<td>
										<dx:ASPxTextBox ID="txtEmail" runat="server" Width="170px">
										</dx:ASPxTextBox>
									</td>
								</tr>
								<tr>
									<td align="right">
										<dx:ASPxLabel ID="ASPxLabel7" runat="server" Text="Notes">
										</dx:ASPxLabel>
									</td>
									<td>
										<dx:ASPxMemo ID="txtNotes" runat="server" Height="71px" Width="170px">
										</dx:ASPxMemo>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
				<br />
				<table width="100%">
					<tr>
						<td align="center" style="background-color: #f4f4f4;">
							<dx:ASPxButton runat="server" ID="ASPxButton1" AutoPostBack="false" UseSubmitBehavior="false"
								Width="5px">
								<ClientSideEvents Click="function (s,e){    e.processOnServer  = false;popFinish.Hide(); }" />
								<ClientSideEvents Click="function (s,e){    e.processOnServer  = false;popFinish.Hide(); }">
								</ClientSideEvents>
								<Image Url="~/Images/close3.png">
								</Image>
							</dx:ASPxButton>
							Cancel
						</td>
						<td style="background-color: #f4f4f4; width: 100%">
							<img src="../Images/seperator.png" />
						</td>
						<td align="center" style="background-color: #f4f4f4;">
							<dx:ASPxButton runat="server" ID="btnFinish" OnClick="btnFinish_Click" Width="5px">
								<Image Url="~/Images/finish.png">
								</Image>
							</dx:ASPxButton>
							Finish
						</td>
					</tr>
				</table>
			</dx:PopupControlContentControl>
		</ContentCollection>
	</dx:ASPxPopupControl>
	<div id="summary7c" style="display: none; width: 100%;">
		<dx:ASPxGridView ID="gvHeader" runat="server" AutoGenerateColumns="False" Styles-Cell-Wrap="False"
			Width="100%" OnHtmlDataCellPrepared="gvHeader_HtmlDataCellPrepared">
			<Columns>
				<dx:GridViewDataTextColumn FieldName="GruppoTex" VisibleIndex="0">
				</dx:GridViewDataTextColumn>
				<dx:GridViewDataTextColumn FieldName="MtInMagazzino" VisibleIndex="1">
					<PropertiesTextEdit DisplayFormatString="{0:n2} mt.">
					</PropertiesTextEdit>
				</dx:GridViewDataTextColumn>
				<dx:GridViewDataTextColumn FieldName="ValoreTex" VisibleIndex="2">
					<PropertiesTextEdit DisplayFormatString="€ {0:n2}">
					</PropertiesTextEdit>
				</dx:GridViewDataTextColumn>
			</Columns>
			<SettingsPager Visible="False">
			</SettingsPager>
		</dx:ASPxGridView>
	</div>
	<table width="100%">
		<tr>
			<td valign="top" align="right" style="width: 100%">
				&nbsp;
			</td>
			<td valign="top" align="right">
				<dx:ASPxCheckBox runat="server" ID="chkRes" Text="Reservation Mode" AllowGrayedByClick="False"
					AutoPostBack="True" OnCheckedChanged="chkRes_CheckedChanged" TextAlign="Left">
				</dx:ASPxCheckBox>
			</td>
		</tr>
		<tr>
			<td valign="top" align="right" style="width: 100%">
				<dx:ASPxLabel ID="lblDetail" runat="server" Text="Details">
				</dx:ASPxLabel>
			</td>
			<td valign="top" align="right">
				<dx:ASPxDropDownEdit ClientInstanceName="checkComboBox" ID="ddeDetailLevel" Width="276px"
					runat="server" EnableAnimation="False">
					<DropDownWindowTemplate>
						<dx:ASPxListBox ID="listBox" ClientInstanceName="checkListBox" SelectionMode="CheckColumn"
							runat="server" SkinID="CheckComboBoxListBox" Width="100%">
							<Border BorderStyle="None" />
							<BorderBottom BorderStyle="Solid" BorderWidth="1px" BorderColor="#DCDCDC" />
							<Items>
								<dx:ListEditItem Text="Brand" Value="Brand" />
								<dx:ListEditItem Text="Season" Value="Season" />
								<dx:ListEditItem Text="Owner" Value="Owner" />
								<dx:ListEditItem Text="OrderRef" Value="OrderRef" />
								<dx:ListEditItem Text="CustomerCode" Value="CustomerCode" />
								<dx:ListEditItem Text="Grup7C" Value="Grup7C" />
								<dx:ListEditItem Text="Desc7C" Value="Desc7C" />
							</Items>
							<ClientSideEvents SelectedIndexChanged="OnListBoxSelectionChanged" />
						</dx:ASPxListBox>
						<table style="width: 100%" cellspacing="0" cellpadding="3">
							<tr>
								<td align="right">
									<dx:ASPxButton ID="btnClose" OnClick="btnClose_click" runat="server" Text="OK">
									</dx:ASPxButton>
								</td>
							</tr>
						</table>
					</DropDownWindowTemplate>
					<ClientSideEvents TextChanged="SynchronizeListBoxValues" DropDown="SynchronizeListBoxValues" />
				</dx:ASPxDropDownEdit>
			</td>
		</tr>
	</table>
	<table width="100%">
		<tr>
			<td align="right">
				<table style="text-align: left">
					<tr>
						<td valign="top" align="right">
							<dx:ASPxButton ID="btnExport" runat="server" OnClick="btnExport_Click" ToolTip="Export To Excel"
								Text="Export">
								<Image Url="~/Images/Excel.png">
								</Image>
							</dx:ASPxButton>
						</td>
						<td valign="top" align="right">
							<dx:ASPxButton ID="btnSummary" runat="server" ToolTip="Summary" Text="Summary" AutoPostBack="False">
								<ClientSideEvents Click="function(s, e) {
	showSummary();
}" />
								<Image Url="~/Images/invoice.png">
								</Image>
							</dx:ASPxButton>
						</td>
						<td>
							<dx:ASPxButton ID="btnMyReservations" runat="server" OnClick="btnMyReservations_Click"
								ToolTip="My Reservations" Text="My Reservations">
								<Image Url="~/Images/stock.png">
								</Image>
							</dx:ASPxButton>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td align="right" class="bgStep">
				<asp:Panel runat="server" ID="pnlRes">
					<table style="text-align: left">
						<tr>
							<td>
								<img src="../Images/seperator.png" />
								<img class="tt" style="cursor: pointer" src="../Images/help1.png" />
								<div class="tooltip">
									Select rows and then select the action.You can use checkboxes or mouse ctrl/shift
									combinations.
								</div>
							</td>
							<td>
								<img src="../Images/seperator.png" />
							</td>
							<td>
								<dx:ASPxLabel ID="lblRes" runat="server" Text="Reserve">
								</dx:ASPxLabel>
							</td>
							<td>
								<dx:ASPxSpinEdit ID="txtQtyRequest" runat="server" AllowNull="False" DisplayFormatString="{0:n0} meter(s)"
									Height="21px" Increment="10" LargeIncrement="50" Number="50" NumberType="Integer"
									MaxValue="10000" MinValue="1" Width="100px" />
							</td>
							<td>
								<img class="tt" style="cursor: pointer" src="../Images/manual.png" onclick="gvcRezerve.PerformCallback('manual');" />
								<div class="tooltip">
									<br />
									Select the quantity specified by the spinner on the left.</div>
							</td>
							<td>
								<img src="../Images/seperator.png" />
							</td>
							<td>
								<img class="tt" style="cursor: pointer" src="../Images/all.png" onclick="gvcRezerve.PerformCallback('all');" />
								<div class="tooltip">
									<br />
									&nbsp;Select all the available quantity.
								</div>
							</td>
							<td>
								<img src="../Images/seperator.png" />
							</td>
							<td>
								<img class="tt" style="cursor: pointer" src="../Images/close.png" onclick="gvcRezerve.PerformCallback('cancel');" />
								<div class="tooltip">
									<br />
									&nbsp;&nbsp;Clear the selection.</div>
							</td>
							<td>
								<img src="../Images/seperator.png" />
							</td>
							<td>
								<img class="tt" style="cursor: pointer" src="../Images/save.png" onclick="popFinish.Show();" />
								<div class="tooltip">
									<br />
									&nbsp;&nbsp;Save & Send Reservation Request</div>
							</td>
						</tr>
					</table>
				</asp:Panel>
			</td>
		</tr>
	</table>
	<table width="100%">
		<tr>
			<td valign="top">
				<table>
					
					<tr>
						<td>
							<dx:ASPxPanel ID="pnlFilter" runat="server">
							</dx:ASPxPanel>
						</td>
					</tr>
				</table>
			</td>
			<td valign="top" style="width: 100%">
				<dx:ASPxTabControl ID="tab" runat="server" ActiveTabIndex="0" OnActiveTabChanged="tab_ActiveTabChanged"
					Width="100%" AutoPostBack="True" OnActiveTabChanging="tab_ActiveTabChanging">
					<Tabs>
						<dx:Tab Text="My Stock">
							<TabImage Url="../images/man.png">
							</TabImage>
						</dx:Tab>
						<dx:Tab Text="Karbel Stock">
							<TabImage Url="../images/k.png">
							</TabImage>
						</dx:Tab>
						<dx:Tab Text="Espresso Stock">
							<TabImage Url="../images/espresso1.png">
							</TabImage>
						</dx:Tab>
					</Tabs>
				</dx:ASPxTabControl>
				<table width="100%">
					<tr>
						<td style="width: 100%">
							<dx:ASPxGridView ID="gvRezerve" runat="server" Width="100%" ClientInstanceName="gvcRezerve"
								AutoGenerateColumns="False" KeyFieldName="ProductId" EnableRowsCache="False"
								OnCustomCallback="gvRezerve_CustomCallback" OnHtmlRowPrepared="gvRezerve_HtmlRowPrepared"
								Styles-SelectedRow-BackColor="Orange" OnHtmlDataCellPrepared="gvRezerve_HtmlDataCellPrepared">
								<Settings ShowFilterRow="True" ShowFilterRowMenu="True" ShowFilterBar="Visible" ShowFooter="True"
									ShowHeaderFilterButton="True" />
								<ClientSideEvents RowClick="function(s, e) {rowClick(s,e);}" />
								<SettingsBehavior AllowSelectByRowClick="true" />
							</dx:ASPxGridView>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	
	<br />
</asp:Content>
